<?php
/**
 * Created by PhpStorm.
 * User: Asnyc
 * Date: 2017/12/29
 * Time: 14:31
 */

namespace app\api\validate;


use app\lib\exception\ParameterException;

class OrderPlace extends BaseValidate
{
    protected $products = [

    ];

    protected $rule = [
        'products' => 'checkProducts'
    ];

    protected $singleRule = [
        'products_id' => 'require|isPositiveInteger',
        'count' => 'require|isPositiveInteger',
    ];

    protected function checkProducts($value){
        if(is_array($value)){
            throw new ParameterException([
                'msg' => 'Σ(っ°Д°;)っ商品参数不正确呀!'
            ]);
        }

        if(empty($value)){
            throw new ParameterException([
                'msg' => '!!!∑(ﾟДﾟノ)ノ商品列表怎么能是空的呢?'
            ]);
        }
    }

    protected function checkProduct($value)
    {
        $validate = new BaseValidate($this->singleRule);
        $result = $validate->check($value);
        if(!$result){
            throw new ParameterException([
                'msg' => ''
            ]);
        }
    }

}